define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cashlist/index' + location.search,
                    edit_url: 'cashlist/edit',
                    dragsort_url:'',
                    cash_url:'cash/index',
                    table: 'table',
                },
                commonSearch: false,
                search: false,
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', operate:false,title: __('Id')},
                        {field: 'htitle',operate:false, title: __('Hotelname')},
                        {field: 'money',operate:false, title: __("Income")},
                        {field: 'appcreatetime',operate:false, title:__("Createtime")},
                        {field: 'appupdtime',operate:false, title:__("Updtime")},
                        {field: 'status', title: __('Status'),searchList:{"1":__('Status0'),"2":__('Status1')},formatter:Table.api.formatter.normal},
                        {field: 'payment', title: __('Payment'),searchList:{"0":__('Payment0'),"1":__('Payment1')},formatter:Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table,events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });


            // 为表格绑定事件
            Table.api.bindevent(table);
            table.on('post-body.bs.table',function () {

                $(".btn-editone").data("title", "财务审批"); //自定义弹窗标题
                $(".btn-editone").data("area", ["80%","80%"]);//修改弹窗大小
            });


        },
        add: function () {

            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
            $(".btn-refresh").trigger('click');

            //自定义弹出列表窗口

            $(document).on("click",".cashlist",function () {


                var ids = $(this).attr("ids")
                if(ids == ""){
                    alert("无数据可以显示")
                    return
                }


                var url = 'cash?id='+ids;//弹出窗口 add.html页面的（fastadmin封装layer模态框将以iframe的方式将add输出到index页面的模态框里）
                Fast.api.open(url, "提现数据【订单记录】", {
                    'area':[
                        $(window).width() > 800 ? '95%' : '800',
                        $(window).height() > 600 ? '95%' : '600'
                    ],
                });

            })


            //parent.location.reload();//刷新这个页面

        },
        retprice: function () {//没新增一个弹窗页面 这里都要配置，否则 执行成功后 无法关闭弹窗
            Controller.api.bindevent();
            setTimeout(function () {
                $("#c-type").trigger("change");
            }, 100);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));

            }
        }
    };




    //申请退款
    $("#applyMoney").click(function () {
        var Oids = $("#c-orderIds").val();
        layer.confirm('是否确定申请退款?', {icon: 3, title:'申请退款'}, function(index){

            $.ajax({
                type: "POST",
                url: "order/applyMoney",
                data: {Oids:Oids},
                dataType: "json",
                success: function(data){
                    if(data.code == 1){
                        layer.msg(data.msg,{time:2000,icon: 6})
                        $("#applyMoney").attr("disabled","disabled");
                    }else{
                        layer.msg(data.msg,{time:2000,icon: 5})
                        return false;
                    }

                }
            });

            layer.close(index);
        });

    })


    //执行退款
    $("#doReturnMoney").click(function () {
        var Oids = $("#c-orderIds").val();
        layer.confirm('是否确定执行退款，操作不可回退?', {icon: 3, title:'执行退款'}, function(index){

            $.ajax({
                type: "POST",
                url: "order/doreturnprice",
                data: {Oids:Oids},
                dataType: "json",
                success: function(data){
                    if(data.code == 1){
                        layer.msg(data.msg,{time:2000,icon: 6})
                        $("#doReturnMoney").attr("disabled","disabled");
                    }else{
                        layer.msg(data.msg,{time:2000,icon: 5})
                        return false;
                    }

                }
            });

            layer.close(index);
        });

    })






    return Controller;
});
